<%@ page contentType="text/html;charset=UTF-8"%>
<script type="text/javascript">
	//是否服务器分页
	var _isServerPage = true;
	//表格列定义
	var _tableCols = 	[{
		data : "uuid",
		sortable : false,
		className : "center",
		width : "30",
		render : RapDataTableUtils.renderCheckCol
	},
	{
		data : 'yearMonth',
		width : "120",
		//render : function(data, type, full){},
		sortable : true
	},
	{
		data : 'type',
		width : "120",
		render : function(data, type, full){
			return RapDataUtils.getEnumName("stwy_waterType", data);
		},
		sortable : true
	},
	{
		data : 'custom.theName',
		width : "120",
		//render : function(data, type, full){},
		sortable : true
	},
	{
		data : 'asset.theName',
		width : "120",
		//render : function(data, type, full){},
		sortable : true
	},
	{
		data : 'thisMonth',
		width : "120",
		className:"rap-td-number",
		render:milliFormat,
		sortable : true
	},
	{
		data : 'actual',
		width : "120",
		className:"rap-td-number",
		render:milliFormat,
		sortable : true
	},
	{
		data : 'share',
		width : "120",
		className:"rap-td-number",
		render:milliFormat,
		sortable : true
	},
	{
		data : 'chargeAmount',
		width : "120",
		className:"rap-td-number",
		render:milliFormat,
		sortable : true
	},
	{
		data : 'planUnitPrice',
		width : "120",
		className:"rap-td-number",
		render:milliFormat,
		sortable : true
	},
	{
		data : 'price',
		width : "120",
		className:"rap-td-number",
		render:milliFormat,
		sortable : true
	},
	{
		data : "uuid",
		className : "center",
		sortable : false,
		render : function(data, type, full) {
			return "<div class='rap-btn-actiongroup'>" 
			+ "<button id='rap-btn-view-row' class='btn btn-xs btn-success' data-rel='tooltip' title='查看'><i class='fa fa-search-plus'></i></button>"
			<shiro:hasPermission name="stwy:bills:waterbills:update">
			+ "<button id='rap-btn-edit-row' class='btn btn-xs btn-info' data-rel='tooltip' title='编辑'><i class='fa fa-edit'></i></button>"
			</shiro:hasPermission>
			<shiro:hasPermission name="stwy:bills:waterbills:delete">
			+ "<button id='rap-btn-remove-row' class='btn btn-xs btn-danger' data-rel='tooltip' title='删除'><i class='fa fa-trash-o'></i></button>"
			</shiro:hasPermission>
			+ "</div>";
		},
		width : "80"
	}]
;

	//宏：生成ShowData方法，在编辑框显示记录数据
	function showData(data) {
		$("input[name='uuid']").val(data.uuid);
		$("input[name='yearMonth']").val(data.yearMonth);
		$("input[name='custom.uuid']").val(data.custom.uuid);
		$("input[name='asset.uuid']").val(data.asset.uuid);
		$("input[name='custom.theName']").val(data.custom.theName);
		$("input[name='asset.theName']").val(data.asset.theName);
		$("input[name='customName']").val(data.custom.theName);
		$("input[name='assetName']").val(data.asset.theName);
		$("input[name='thisMonth']").val(data.thisMonth);
		$("input[name='actual']").val(data.actual);
		$("input[name='share']").val(data.share);
		$("input[name='chargeAmount']").val(data.chargeAmount);
		$("input[name='planUnitPrice']").val(data.planUnitPrice);
		$("input[name='price']").val(data.price);
		$("textarea[name='remark']").val(data.remark);
		$("select[name='type']").val(data.type);
	}
	
	function onRefresh() {
		if(_isServerPage)
			_tableList.draw();	//服务器分页
		else
			loadList();		//非服务器分页
	}
	function callbackAsset(data){
		$("#assetId").val(data.uuid);
		$("#assetName").val(data.theName);
	}
	function callbackCustom(data){
		$("#customId").val(data.uuid);
		$("#customName").val(data.theName);
	}
	function bindOtherActions(){
		$('#assetName').bind('focus', function(){
			$("#rap-btn-ref-asset").click();
		});
		$("#rap-btn-ref-asset").colorbox({
			iframe : true,
			opacity	: 0.2,
			transition : 'none',
			speed : 200,
			href : "${ctx}/pro/asset/select?search_EQ_status=1&callback=callbackAsset&isSingle=true",
			innerWidth : '90%',
			innerHeight : '80%',
			close : '×',
			fixed : true
		});
		$('#customName').bind('focus', function(){
			$("#rap-btn-ref-custom").click();
		});
		$("#rap-btn-ref-custom").colorbox({
			iframe : true,
			opacity	: 0.2,
			transition : 'none',
			speed : 200,
			href : "${ctx}/custom/select?search_EQ_status=1&callback=callbackCustom&isSingle=true",
			innerWidth : '90%',
			innerHeight : '80%',
			close : '×',
			fixed : true
		});
	}
	$(document).ready(function() {
		bindDefaultActions();
		bindOtherActions();
		if(_isServerPage){
			//服务器分页
			serverPage();	
		}else{
			//非服务器分页
			_tableList = $('#rap-table-list').DataTable({
				"columns" : _tableCols,
				"createdRow" : RapDataTableUtils.setActions,
				"order": [] 
			});
			loadList();		
		}
		
		RapDataTableUtils.setCheckCol(_tableList);

		/**
		 * 表单校验
		 */
		_validator = $('#rap-form-edit').validate({
					rules : {
						yearMonth : {
							required : true
						},
						type : {
							required : true
						},
						customName : {
							required : true
						},
						assetName : {
							required : true
						},
						thisMonth:{
							isNumber:true
						},
						actual:{
							isNumber:true
						},
						share:{
							isNumber:true
						},
						chargeAmount:{
							isNumber:true
						},
						planUnitPrice:{
							isNumber:true
						},
						price:{
							isNumber:true
						}
					},
					messages : {
					}
				});
	});
</script>